﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Insight.ComClass;
using Insight.CtrlClass;

namespace InsightQueAPP
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            CtlCnt = 0;
            MaxCnt = 100;
            this.ctl = new Insight.CtrlClass.DeskCtrl[MaxCnt];
            InitializeComponent();
            this.MouseClick += new MouseEventHandler(this.Form1_Load);
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            InsightConst.DRIVER = InsightString.EncryptStr("{SQL Server}");
            InsightConst.SERVER = InsightString.EncryptStr("ms0801.gabiadb.com");
            InsightConst.UID = InsightString.EncryptStr("insightque");
            InsightConst.PWD = InsightString.EncryptStr("insight");

            string query = querybox.Text.Trim();

            DataTable aYSRTable = InsightConnect.ISTExecuteFill(query, "STATCOLS");

            //DataTable tb = InsightConnect.fetchData(query);
           
            foreach (DataColumn dc in aYSRTable.Columns)
            {
                DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
                column.DataPropertyName = dc.ColumnName;
                column.HeaderText = dc.ColumnName;
                column.Name = dc.ColumnName;
                column.SortMode = DataGridViewColumnSortMode.Automatic;
                column.ValueType = dc.DataType;
                userDataGridView.Columns.Add(column);
            }
            userDataGridView.DataSource = aYSRTable;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            this.toolTip1.SetToolTip(this.button3, "이름 : 신세호\r\n나이: 30");
            this.toolTip1.SetToolTip(this.button4, "이름 : 김태희\r\n나이: 31");
            this.toolTip1.SetToolTip(this.button5, "이름 : 한가인\r\n나이: 30");
            this.toolTip1.SetToolTip(this.button6, "이름 : 최종우\r\n나이: 29");
        }

        private void button7_Click(object sender, EventArgs e)
        {
            this.panel2.SuspendLayout();
            this.panel1.Controls.Add(this.panel2);
            this.panel2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(224)))), ((int)(((byte)(192)))));
         //   
           // 
           // 
           // 
            this.panel2.Location = new System.Drawing.Point(3, 133);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(270, 155);
            this.panel2.TabIndex = 8;
        }

        private void Form1_Load(object sender, MouseEventArgs e)
        {
            if (MaxCnt > CtlCnt)
            {
                if (MouseButtons.Left == e.Button)
                {
                    this.ctl[CtlCnt] = new Insight.CtrlClass.DeskCtrl();

                    this.ctl[CtlCnt].Location = new System.Drawing.Point(e.X, e.Y);
                    this.ctl[CtlCnt].Name = "userControl";
                    this.ctl[CtlCnt].Size = new System.Drawing.Size(127, 129);
                    this.ctl[CtlCnt].TabIndex = 0;
                    this.ctl[CtlCnt].SetDeskInfo(CtlCnt.ToString());

                    this.Controls.Add(this.ctl[CtlCnt]);
                    CtlCnt++;
                }
                else if (MouseButtons.Right == e.Button)
                {
                    this.Controls.Remove(this.ctl[CtlCnt - 1]);
                    CtlCnt--;
                }
            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
            this.button11.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
            this.button10.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
        }

        private Insight.CtrlClass.DeskCtrl[] ctl;
        private int CtlCnt;
        private int MaxCnt;

        private void button4_Click(object sender, EventArgs e)
        {

        }
    }
}
